Pre-create the output doc directory
authorAlex Crichton <alex@alexcrichton.com>
Tue, 13 Oct 2015 17:31:40 +0000 (10:31 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Tue, 13 Oct 2015 23:02:34 +0000 (16:02 -0700)
Cargo will run rustdoc concurrently if it can, and rustdoc is instructed to
place output in a central location. Rustdoc itself knows how to handle
concurrent invocations, but it requires that the output location exists for this
to work correctly (as otherwise the rustdoc processes will race to create the
directory). While this may also be fixable upstream, for now just precreate the
doc directory to ensure that rustdoc doesn't race trying to create it.

src/cargo/ops/cargo_rustc/mod.rs
tests/test_cargo_doc.rs

index 8461f4837830bb7cdec09bf773f14533ba9a442e..5feb3359195639f44579dafa951e4895c97c42a2 100644 (file)
@@ -380,8 +380,13 @@ fn rustdoc(cx: &mut Context, unit: &Unit) -> CargoResult<Work> {
         rustdoc.arg("--target").arg(target);
         doc_dir.push(target);
     }
-
     doc_dir.push("doc");
+
+    // Create the documentation directory ahead of time as rustdoc currently has
+    // a bug where concurrent invocations will race to create this directory if
+    // it doesn't already exist.
+    try!(fs::create_dir_all(&doc_dir));
+
     rustdoc.arg("-o").arg(doc_dir);
 
     if let Some(features) = cx.resolve.features(unit.pkg.package_id()) {
index 232be534c2d2f4023e40b7bebcf9b96ec1382bd9..031870c55a965c7fd796b9a2eae7245276dbdce8 100644 (file)
@@ -470,7 +470,10 @@ test!(doc_multiple_deps {
             pub fn baz() {}
         "#);
 
-    assert_that(p.cargo_process("doc").arg("-p").arg("bar").arg("-p").arg("baz"),
+    assert_that(p.cargo_process("doc")
+                  .arg("-p").arg("bar")
+                  .arg("-p").arg("baz")
+                  .arg("-v"),
                 execs().with_status(0));
 
     assert_that(&p.root().join("target/doc"), existing_dir());